package applicationFunction.hessian.helloworld;

import applicationFunction.hessian.helloWorld.BasicAPI;
import com.caucho.hessian.client.HessianProxyFactory;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;


/**
 * 加上log也会出问题
 */
public class Client {
    private static Logger logger = null;
    public static void main(String[] args) {
        try {

            initLog();
            String url = "";

            HessianProxyFactory factory = new HessianProxyFactory();
            BasicAPI basic = null;

//            factory.create(url);
            basic = (BasicAPI) factory.create(BasicAPI.class, url);

            String result  = basic.hello();
            System.out.println("hello(): " + result);
        } catch (Exception e) {
            System.out.println("into Exception");
            e.printStackTrace();//如果不调用这个就不会出现
            System.out.println("finish Exception");
        }catch (Throwable t){
            System.out.println("into Error");
            t.printStackTrace();
            System.out.println("finish Error");
        }
        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaa");


    }

    public static void initLog() throws IOException {
        logger = Logger.getLogger("");
        System.setProperty("java.util.logging.SimpleFormatter.format","%1$s # %2$s # %3$s # %4$s # %5$s # %6$s%n");
        logger.setLevel(Level.ALL);
        FileHandler fileHandler = new FileHandler("HessianClient.log");
        SimpleFormatter sf = new SimpleFormatter();
        fileHandler.setFormatter(sf);
        logger.addHandler(fileHandler);
    }
}
